﻿@{
    ViewBag.Title = "AddStock";
    Layout = "~/Views/Shared/_Layout.cshtml";
}



<table>
    <tbody>
        <tr>
            <td>
                商品名称
            </td>
            <td>
                @*@Html.DropDownList("Pid")*@
                <select id="Select1">
                    <option>---请选择---</option>

                </select>
            </td>
        </tr>
        <tr>
            <td>现货库存</td>
            <td><input id="Text1" type="text" /></td>
        </tr>
        <tr>
            <td>可用库存量</td>

            <td><input id="Text2" type="text" /></td>
        </tr>
        <tr>
            <td>库存状态</td>
            <td><input id="Text3" type="text" /></td>
        </tr>
        <tr>
            <td>合计</td>
            <td><input id="Text4" type="text" /></td>
        <tr>
            <td>
                <input id="Button1" type="button" value="添加" onclick="Add()" />
            </td>

        </tr>
    </tbody>
</table>

<script>
    $(document).ready(function () {
        $.ajax({
            url: "/Home/ShowPid",
            type: "get",
            success: function (d) {
                $(d).each(function (index,item) {
                    var i = "<option value=" + item.Pid + ">" + item.Pname + "</option>"
                    $("#Select1").append(i);
                })
            }
        })
    })
    function Add()
    {
        var SpotStocks = $("#Text1").val();
        var AvailableStocks = $("#Text2").val();
        var StockState = $("#Text3").val();
        var Sum = $("#Text4").val();
        var Pid = $("#Select1").val();
        $.ajax({
            url: "/Home/AddSto",
            type: "post",
            data: {

                SpotStocks:SpotStocks,
                AvailableStocks: AvailableStocks,
                StockState: StockState,
                Sum: Sum,
                Pid:Pid

            },
            success: function (data) {
                if(data="1")
                {
                    alert('添加成功')
                    location.href = '/Home/KucunShow'
                }
                else
                {
                    alert('系统繁忙，请稍后重试')
                }
            }
        })
    }

</script>